namespace designpatternsplusplus.decorator.RepositoryServices
{
    #region

    using System;
    using System.Collections.ObjectModel;
    using designpatternsplus.contracts;
    using DomainEntities;

    #endregion

    /// <summary>
    /// Emulates a master repository store
    /// as a singleton
    /// 
    /// I prefer this style in implementation
    /// as I like the lazy load option where I can
    /// use an internal class
    /// The static class is not as flexible
    /// </summary>
    [Serializable]
    public class ProductRepository : KeyedCollection<Guid, ISkuDetails>, IProductRepository
    {
        /// <summary>
        /// Gets the Products.
        /// This is immutable for the session
        /// </summary>
        /// <returns></returns>
        public ProductRepository()
        {
            var _productsLocalCache = new[]
                                      {
                                          new SkuDetails
                                          {
                                              Sku = "ED22DA7410E145b7BED25CF93DA776C9",
                                              Type =
                                                  new ProductType
                                                  (ItemCategory.NietzcheThusSpoke),
                                              IsImported = false,
                                              RetailPrice = 12.49
                                          }, new SkuDetails
                                             {
                                                 Sku = "10B2C00BD2B64821B00554F2ED0B837B",
                                                 Type =
                                                     new ProductType
                                                     (ItemCategory.
                                                          TheSmithsLouderThanBombsMusicCd),
                                                 IsImported = false,
                                                 RetailPrice = 14.99
                                             }, new SkuDetails
                                                {
                                                    Sku =
                                                        "73E11A6F53CF4b949F762F7C59210C18",
                                                    Type =
                                                        new ProductType
                                                        (ItemCategory.HersheysCandyBar),
                                                    IsImported = false,
                                                    RetailPrice = .85
                                                }, new SkuDetails
                                                   {
                                                       Sku =
                                                           "2F301C01-082D-446d-B339-CC21602E230D",
                                                       Type =
                                                           new ProductType
                                                           (ItemCategory.
                                                                ChocolateInBoxPieces),
                                                       IsImported = true,
                                                       RetailPrice = 10.00
                                                   }, new SkuDetails
                                                      {
                                                          Sku =
                                                              "A4D14FF8411F462495021F012E4356DF",
                                                          Type =
                                                              new ProductType
                                                              (ItemCategory.
                                                                   PerfumeTopFrenchBrand),
                                                          IsImported = true,
                                                          RetailPrice = 47.50
                                                      }, new SkuDetails
                                                         {
                                                             Sku =
                                                                 "75173395EB274d7bB51B149E8144B6FE",
                                                             Type =
                                                                 new ProductType
                                                                 (ItemCategory.
                                                                      PerfumeMadeInChina),
                                                             IsImported = true,
                                                             RetailPrice = 27.99
                                                         }, new SkuDetails
                                                            {
                                                                Sku =
                                                                    "5FB5B42F99954d7186CDCF5AC26C2FD3",
                                                                Type =
                                                                    new ProductType
                                                                    (ItemCategory.
                                                                         PerfumeJerseysFinest),
                                                                IsImported = false,
                                                                RetailPrice = 18.99
                                                            }, new SkuDetails
                                                               {
                                                                   Sku =
                                                                       "0FBE1DD511F243acBF6099B929A595BD",
                                                                   Type =
                                                                       new ProductType
                                                                       (ItemCategory.
                                                                            PharmacyAhMyHeadHurts),
                                                                   IsImported = false,
                                                                   RetailPrice = 9.75
                                                               }, new SkuDetails
                                                                  {
                                                                      Sku =
                                                                          "A77727F541604a0cBDD416689E486869",
                                                                      Type =
                                                                          new ProductType
                                                                          (ItemCategory.
                                                                               ChocolateImportedGoodPrice),
                                                                      IsImported = true,
                                                                      RetailPrice = 11.25
                                                                  },
                                      };

            foreach (var item in _productsLocalCache)
                Add(item);
        }

        /// <summary>
        /// When implemented in a derived class, extracts the key from the specified element.
        /// </summary>
        /// <returns>
        /// The key for the specified element.
        /// </returns>
        /// <param name="sku">The element from which to extract the key.</param>
        protected override Guid GetKeyForItem(ISkuDetails sku)
        {
            return new Guid(sku.Sku);
        }
    }
}